#Boa:Frame:pedEntradaFrame

import wx
import wx.grid

from CONTROLE import *


def create(parent):
    return pedEntradaFrame(parent)

[wxID_PEDENTRADAFRAME, wxID_PEDENTRADAFRAMEALTERABTN, 
 wxID_PEDENTRADAFRAMECANCELABTN, wxID_PEDENTRADAFRAMECODIGO, 
 wxID_PEDENTRADAFRAMEEXCLUIBTN, wxID_PEDENTRADAFRAMEFECHAPEDIDO, 
 wxID_PEDENTRADAFRAMEINSEREITEMBTN, wxID_PEDENTRADAFRAMELISTBOX1, 
 wxID_PEDENTRADAFRAMENOVOBTN, wxID_PEDENTRADAFRAMEP, 
 wxID_PEDENTRADAFRAMEPESQITEMBTN, wxID_PEDENTRADAFRAMEPESQUISABTN, 
 wxID_PEDENTRADAFRAMEREMOVEITEMBTN, wxID_PEDENTRADAFRAMESALVABTN, 
 wxID_PEDENTRADAFRAMESTATICBOX1, wxID_PEDENTRADAFRAMESTATICBOX2, 
 wxID_PEDENTRADAFRAMESTATICTEXT1, wxID_PEDENTRADAFRAMESTATICTEXT10, 
 wxID_PEDENTRADAFRAMESTATICTEXT2, wxID_PEDENTRADAFRAMESTATICTEXT3, 
 wxID_PEDENTRADAFRAMESTATICTEXT4, wxID_PEDENTRADAFRAMESTATICTEXT5, 
 wxID_PEDENTRADAFRAMESTATICTEXT6, wxID_PEDENTRADAFRAMESTATICTEXT7, 
 wxID_PEDENTRADAFRAMESTATICTEXT8, wxID_PEDENTRADAFRAMESTATICTEXT9, 
 wxID_PEDENTRADAFRAMETEXTCTRL1, wxID_PEDENTRADAFRAMETEXTCTRL10, 
 wxID_PEDENTRADAFRAMETEXTCTRL11, wxID_PEDENTRADAFRAMETEXTCTRL2, 
 wxID_PEDENTRADAFRAMETEXTCTRL3, wxID_PEDENTRADAFRAMETEXTCTRL4, 
 wxID_PEDENTRADAFRAMETEXTCTRL5, wxID_PEDENTRADAFRAMETEXTCTRL6, 
 wxID_PEDENTRADAFRAMETEXTCTRL7, wxID_PEDENTRADAFRAMETEXTCTRL8, 
 wxID_PEDENTRADAFRAMETEXTCTRL9, 
] = [wx.NewId() for _init_ctrls in range(37)]

class pedEntradaFrame(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_PEDENTRADAFRAME,
              name=u'pedEntradaFrame', parent=prnt, pos=wx.Point(555, 234),
              size=wx.Size(762, 473), style=wx.DEFAULT_FRAME_STYLE,
              title=u'Entrada de Mercadorias')
        self.SetClientSize(wx.Size(746, 435))

        self.staticText1 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT1,
              label=u'Entrada de Mercadorias', name='staticText1', parent=self,
              pos=wx.Point(248, 8), size=wx.Size(222, 25), style=0)
        self.staticText1.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticBox1 = wx.StaticBox(id=wxID_PEDENTRADAFRAMESTATICBOX1,
              label=u'Informa\xe7\xf5es do Pedido', name='staticBox1',
              parent=self, pos=wx.Point(16, 40), size=wx.Size(712, 104),
              style=0)

        self.Codigo = wx.StaticText(id=wxID_PEDENTRADAFRAMECODIGO,
              label=u'Codigo', name=u'Codigo', parent=self, pos=wx.Point(32,
              80), size=wx.Size(34, 13), style=0)

        self.staticText4 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT4,
              label=u'Data', name='staticText4', parent=self, pos=wx.Point(32,
              120), size=wx.Size(24, 13), style=0)

        self.textCtrl1 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL1,
              name=u'textCtrl1', parent=self, pos=wx.Point(72, 72),
              size=wx.Size(48, 21), style=0, value=u'')
        self.textCtrl1.SetEditable(False)
        self.textCtrl1.Enable(False)

        self.textCtrl4 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL4,
              name=u'textCtrl4', parent=self, pos=wx.Point(72, 112),
              size=wx.Size(64, 21), style=0, value=u'')
        self.textCtrl4.SetEditable(False)
        self.textCtrl4.Enable(False)

        self.novoBtn = wx.Button(id=wxID_PEDENTRADAFRAMENOVOBTN, label=u'novo',
              name=u'novoBtn', parent=self, pos=wx.Point(552, 64),
              size=wx.Size(75, 23), style=0)
        self.novoBtn.Bind(wx.EVT_BUTTON, self.OnNovoBtnButton,
              id=wxID_PEDENTRADAFRAMENOVOBTN)

        self.alteraBtn = wx.Button(id=wxID_PEDENTRADAFRAMEALTERABTN,
              label=u'altera', name=u'alteraBtn', parent=self, pos=wx.Point(552,
              88), size=wx.Size(75, 23), style=0)
        self.alteraBtn.Bind(wx.EVT_BUTTON, self.OnAlteraBtnButton,
              id=wxID_PEDENTRADAFRAMEALTERABTN)

        self.salvaBtn = wx.Button(id=wxID_PEDENTRADAFRAMESALVABTN,
              label=u'salva', name=u'salvaBtn', parent=self, pos=wx.Point(552,
              112), size=wx.Size(75, 23), style=0)
        self.salvaBtn.Bind(wx.EVT_BUTTON, self.OnSalvaBtnButton,
              id=wxID_PEDENTRADAFRAMESALVABTN)

        self.cancelaBtn = wx.Button(id=wxID_PEDENTRADAFRAMECANCELABTN,
              label=u'cancela', name=u'cancelaBtn', parent=self,
              pos=wx.Point(632, 64), size=wx.Size(75, 23), style=0)
        self.cancelaBtn.Bind(wx.EVT_BUTTON, self.OnCancelaBtnButton,
              id=wxID_PEDENTRADAFRAMECANCELABTN)

        self.excluiBtn = wx.Button(id=wxID_PEDENTRADAFRAMEEXCLUIBTN,
              label=u'exclui', name=u'excluiBtn', parent=self, pos=wx.Point(632,
              88), size=wx.Size(75, 23), style=0)
        self.excluiBtn.Bind(wx.EVT_BUTTON, self.OnExcluiBtnButton,
              id=wxID_PEDENTRADAFRAMEEXCLUIBTN)

        self.pesquisaBtn = wx.Button(id=wxID_PEDENTRADAFRAMEPESQUISABTN,
              label=u'pesquisar', name=u'pesquisaBtn', parent=self,
              pos=wx.Point(632, 112), size=wx.Size(75, 23), style=0)
        self.pesquisaBtn.Bind(wx.EVT_BUTTON, self.OnPesquisaBtnButton,
              id=wxID_PEDENTRADAFRAMEPESQUISABTN)

        self.staticBox2 = wx.StaticBox(id=wxID_PEDENTRADAFRAMESTATICBOX2,
              label=u'Itens do Pedido', name='staticBox2', parent=self,
              pos=wx.Point(16, 160), size=wx.Size(712, 264), style=0)

        self.staticText2 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT2,
              label=u'Codigo', name='staticText2', parent=self, pos=wx.Point(32,
              224), size=wx.Size(34, 13), style=0)

        self.textCtrl7 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL7,
              name=u'textCtrl7', parent=self, pos=wx.Point(32, 240),
              size=wx.Size(48, 21), style=0, value=u'')
        self.textCtrl7.Bind(wx.EVT_KEY_UP, self.OnTextCtrl7KeyUp)

        self.staticText8 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT8,
              label=u'Quantidade', name='staticText8', parent=self,
              pos=wx.Point(432, 224), size=wx.Size(57, 13), style=0)

        self.textCtrl9 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL9,
              name=u'textCtrl9', parent=self, pos=wx.Point(432, 240),
              size=wx.Size(92, 21), style=0, value=u'')

        self.staticText9 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT9,
              label=u'Pre\xe7o Unitario', name='staticText9', parent=self,
              pos=wx.Point(528, 224), size=wx.Size(68, 13), style=0)

        self.textCtrl10 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL10,
              name=u'textCtrl10', parent=self, pos=wx.Point(528, 240),
              size=wx.Size(92, 21), style=0, value=u'')

        self.staticText10 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT10,
              label=u'Pre\xe7o Total', name='staticText10', parent=self,
              pos=wx.Point(624, 224), size=wx.Size(55, 13), style=0)

        self.textCtrl11 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL11,
              name=u'textCtrl11', parent=self, pos=wx.Point(624, 240),
              size=wx.Size(88, 21), style=0, value=u'')

        self.pesqItemBtn = wx.Button(id=wxID_PEDENTRADAFRAMEPESQITEMBTN,
              label=u'Pesquisa', name=u'pesqItemBtn', parent=self,
              pos=wx.Point(32, 184), size=wx.Size(75, 23), style=0)
        self.pesqItemBtn.Bind(wx.EVT_BUTTON, self.OnPesqItemBtnButton,
              id=wxID_PEDENTRADAFRAMEPESQITEMBTN)

        self.insereItemBtn = wx.Button(id=wxID_PEDENTRADAFRAMEINSEREITEMBTN,
              label=u'Insere', name=u'insereItemBtn', parent=self,
              pos=wx.Point(128, 184), size=wx.Size(75, 23), style=0)
        self.insereItemBtn.Bind(wx.EVT_BUTTON, self.OnInsereItemBtnButton,
              id=wxID_PEDENTRADAFRAMEINSEREITEMBTN)

        self.removeItemBtn = wx.Button(id=wxID_PEDENTRADAFRAMEREMOVEITEMBTN,
              label=u'Remove', name=u'removeItemBtn', parent=self,
              pos=wx.Point(208, 184), size=wx.Size(75, 23), style=0)
        self.removeItemBtn.Bind(wx.EVT_BUTTON, self.OnRemoveItemBtnButton,
              id=wxID_PEDENTRADAFRAMEREMOVEITEMBTN)

        self.fechaPedido = wx.Button(id=wxID_PEDENTRADAFRAMEFECHAPEDIDO,
              label=u'Fechar Pedido', name=u'fechaPedido', parent=self,
              pos=wx.Point(616, 184), size=wx.Size(91, 23), style=0)
        self.fechaPedido.Bind(wx.EVT_BUTTON, self.OnFechaPedidoButton,
              id=wxID_PEDENTRADAFRAMEFECHAPEDIDO)

        self.listBox1 = wx.ListBox(choices=[], id=wxID_PEDENTRADAFRAMELISTBOX1,
              name='listBox1', parent=self, pos=wx.Point(32, 264),
              size=wx.Size(680, 152), style=0)

        self.textCtrl8 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL8,
              name=u'textCtrl8', parent=self, pos=wx.Point(88, 240),
              size=wx.Size(336, 21), style=0, value=u'')

        self.staticText5 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT5,
              label=u'Descri\xe7\xe3o', name='staticText5', parent=self,
              pos=wx.Point(88, 224), size=wx.Size(47, 13), style=0)

        self.staticText3 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT3,
              label=u'Valor Total do Pedido', name='staticText3', parent=self,
              pos=wx.Point(328, 120), size=wx.Size(102, 13), style=0)

        self.textCtrl6 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL6,
              name=u'textCtrl6', parent=self, pos=wx.Point(432, 112),
              size=wx.Size(100, 21), style=0, value=u'')
        self.textCtrl6.SetEditable(False)
        self.textCtrl6.Enable(False)

        self.staticText6 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT6,
              label=u'Fornecedor', name='staticText6', parent=self,
              pos=wx.Point(136, 80), size=wx.Size(56, 13), style=0)

        self.textCtrl2 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL2,
              name=u'textCtrl2', parent=self, pos=wx.Point(200, 72),
              size=wx.Size(48, 21), style=0, value=u'')
        self.textCtrl2.SetEditable(False)
        self.textCtrl2.Enable(False)

        self.textCtrl3 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL3,
              name=u'textCtrl3', parent=self, pos=wx.Point(256, 72),
              size=wx.Size(256, 21), style=0, value=u'')
        self.textCtrl3.SetEditable(False)
        self.textCtrl3.Enable(False)

        self.p = wx.Button(id=wxID_PEDENTRADAFRAMEP, label=u'P', name=u'p',
              parent=self, pos=wx.Point(520, 72), size=wx.Size(16, 23),
              style=0)

        self.staticText7 = wx.StaticText(id=wxID_PEDENTRADAFRAMESTATICTEXT7,
              label=u'Numero', name='staticText7', parent=self,
              pos=wx.Point(152, 120), size=wx.Size(38, 13), style=0)

        self.textCtrl5 = wx.TextCtrl(id=wxID_PEDENTRADAFRAMETEXTCTRL5,
              name=u'textCtrl5', parent=self, pos=wx.Point(200, 112),
              size=wx.Size(104, 21), style=0, value=u'')
        self.textCtrl5.SetEditable(False)
        self.textCtrl5.Enable(False)

    def __init__(self, parent):
        self._init_ctrls(parent)
    
    
    def OnPButton(self, event):
        framee = pesqFornFrame(None)
        framee.Show()

    def OnFechaPedidoButton(self, event):
        event.Skip()

    def OnPesqItemBtnButton(self, event):
        event.Skip()

    def OnInsereItemBtnButton(self, event):
        event.Skip()

    def OnRemoveItemBtnButton(self, event):
        event.Skip()

    def OnNovoBtnButton(self, event):
        c = Controle()
        
        data_atual = c.get_data_atual()
        self.textCtrl1.SetValue('')
        self.textCtrl2.SetValue('')
        self.textCtrl3.SetValue('')
        self.textCtrl4.SetValue(data_atual)
        self.textCtrl5.SetValue('')
        self.textCtrl6.SetValue('')
        self.alterar_campos(True)
        
        
        
        
        

    def OnAlteraBtnButton(self, event):
        self.alterar_campos(True)
    


    def OnSalvaBtnButton(self, event):
        c = Controle()
        cod_forn = self.textCtrl2.GetValue()
        data = self.textCtrl4.GetValue()
        numero = self.textCtrl5.GetValue()
        v_total = self.textCtrl6.GetValue()
        
        
        
        
        atributos = [cod_forn, numero, v_total, cod_forn]
        print atributos
        
        validacao = c.salvar_ped_entrada(atributos)
        
        if validacao == True:
            self.alterar_campos(False)
            
            m = 'Pedido Incluso, Adicione os Itens'
            c = 'Pedido de Entrada'
            wx.MessageBox(m,c,wx.OK)

    def OnCancelaBtnButton(self, event):
        event.Skip()

    def OnExcluiBtnButton(self, event):
        event.Skip()

    def OnPesquisaBtnButton(self, event):
        event.Skip()
        
    def alterar_campos(self, VF):
        
        self.textCtrl2.SetEditable(VF)
        self.textCtrl2.Enable(VF)
        self.textCtrl3.SetEditable(VF)
        self.textCtrl3.Enable(VF)
        self.textCtrl4.SetEditable(VF)
        self.textCtrl4.Enable(VF)
        self.textCtrl5.SetEditable(VF)
        self.textCtrl5.Enable(VF)
        self.textCtrl6.SetEditable(VF)
        self.textCtrl6.Enable(VF)
        self.textCtrl7.SetEditable(VF)
        self.textCtrl7.Enable(VF)
        self.textCtrl8.SetEditable(VF)
        self.textCtrl8.Enable(VF)
        self.textCtrl9.SetEditable(VF)
        self.textCtrl9.Enable(VF)
        self.textCtrl10.SetEditable(VF)
        self.textCtrl10.Enable(VF)
        self.textCtrl11.SetEditable(VF)
        self.textCtrl11.Enable(VF)


    def OnTextCtrl7KeyUp(self, event):
        cod = self.textCtrl7.GetValue()
        print cod
        c = Controle()
        atributos = c.procurar_produto_codigo(cod)
        print atributos
        nome = atributos[1]
        qtd =  1
        preco_venda = atributos[4]
        self.textCtrl8.SetValue(str(nome))
        self.textCtrl9.SetValue(str(qtd))
        self.textCtrl10.SetValue(str(preco_venda))
        self.textCtrl11.SetValue(str(qtd*preco_venda))
